package com.guo.controller;

import org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author ghg
 * @Date 2025/09/25 16:39
 * @Version 1.0
 */
@RestController
public class HomeController {

	@GetMapping("/")
	public String home() {
		return "home"; // 返回主页视图
	}

	@GetMapping("/home")
	public String securedHome(OAuth2AuthenticationToken authentication, Model model) {
		// 将认证信息添加到模型，供页面展示
		if (authentication != null) {
			model.addAttribute("userName", authentication.getName());
			model.addAttribute("userAttributes", authentication.getPrincipal().getAttributes());
		}
		return "home"; // 返回受保护的主页视图
	}
}
